package com.sf.protal.controller;

import com.sf.protal.pojo.Msg;
import com.sf.protal.pojo.UmsConsumer;
import com.sf.protal.service.UmsConsumerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;
import java.util.List;

@Controller
@RequestMapping("/consumer")
public class UmsConsumerController {

	@Autowired
	private UmsConsumerService umsConsumerService;

	@RequestMapping("/list")
	public String getAllConsumerList(Model model){
		List<UmsConsumer> consumers = umsConsumerService.getAllConsumerList();
		model.addAttribute("consumers",consumers);
		return "admin/index";
	}

	@ResponseBody
	@RequestMapping("/contact")
	public Msg addConsumerInfo(UmsConsumer umsConsumer){
		umsConsumer.setCreateTime(new Date());
		umsConsumer.setUpdateTime(new Date());
		umsConsumer.setIntentionLeve(1);
		umsConsumer.setProjectType(1);
		// 1.表示未查看，2表示有意向，3表示意向不大，4，无意向
		umsConsumer.setState(1);
		boolean is = umsConsumerService.addConsumerInfo(umsConsumer);
		if(is){
			return Msg.success();
		}else {
			return Msg.fail();
		}
	}
}
